<template>
  <!--
      	作者：luoyiming
      	时间：2019-06-04
      	描述：插件中心-优惠券-优惠券列表
      -->
  <div class="user">
    <!--搜索表单-->
    <div class="common-seach-wrap">
      <el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="关键词">
          <el-input v-model="formInline.search" placeholder="姓名/手机号/身份证号码"></el-input>
        </el-form-item>
        <el-form-item label="提交时间">
          <div class="block">
            <span class="demonstration"></span>
            <el-date-picker
              size="small"
              v-model="formInline.create_time"
              type="daterange"
              value-format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </div>
        </el-form-item>
        <el-form-item label="状态">
          <el-select size="small" v-model="formInline.status" placeholder="请选择">
            <el-option label="全部" value=""></el-option>
            <el-option label="未处理" value="0"></el-option>
            <el-option label="已处理" value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="product-content">
      <el-form ref="form" :model="form" label-width="100px">
        <div class="table-wrap">
          <el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
            <el-table-column prop="name" label="姓名" width="100"></el-table-column>
            <el-table-column prop="identity_num" label="身份证号码"></el-table-column>
            <el-table-column prop="phone" label="手机号码"></el-table-column>
            <el-table-column prop="city_name" label="所在城市"></el-table-column>
            <el-table-column prop="create_time" label="提交时间"></el-table-column>
            <el-table-column label="状态" width="80" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.status==0" style="color:#C0C4CC">未处理</span>
                <span v-else-if="scope.row.status==1" style="color:green">已处理</span>
              </template>
            </el-table-column>
            <el-table-column prop="remark" label="备注" width="180" >
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="90">
              <template slot-scope="scope">
                <el-button @click="handleClick(scope.row)" type="text" size="small">处理</el-button>
                <el-button @click="deleteClick(scope.row)" type="text" size="small">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form>
      <!--分页-->
      <div class="pagination">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
                       :current-page="curPage"
                       :page-size="pageSize" layout="total, prev, pager, next, jumper"
                       :total="totalDataNumber">
        </el-pagination>
      </div>
    </div>
    <handle :open="handleOpen" :form="handleRow" @close="handleClose"></handle>
  </div>
</template>
<script>
import * as EmployApi from '@/api/employ.js';
import Handle from "./Handle.vue";

export default {
  components: {Handle},
  data() {
    return {
      formInline: {},
      form: {},
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      /*是否加载完成*/
      loading: true,
      handleOpen: false,
      handleRow: {}
    };
  },
  created() {
    /*获取列表*/
    this.getData();
  },
  methods: {
    /*获取列表*/
    getData() {
      let self = this;
      let Params = this.formInline;
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      this.loading = true;
      EmployApi.employList(Params, true)
        .then(data => {
          self.loading = false;
          self.tableData = data.data.list.data;
          self.totalDataNumber = data.data.list.total
        })
        .catch(error => {
          this.loading = false;
        });
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.loading = true;
      self.getData();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getData();
    },
    /*删除优惠券*/
    deleteClick(e) {
      let self = this;
      self.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        self.loading = true;
        EmployApi.deleteEmploy({
          employ_id: e.employ_id
        }, true).then(data => {
          self.loading = false;
          self.$message({
            message: data.msg,
            type: 'success'
          });
          self.getData();

        })
          .catch(error => {
            self.loading = false;
          });

      }).catch(() => {
        self.loading = false;
      });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.getData();
    },
    handleClick(row) {
      this.handleOpen = true;
      this.handleRow = row;
    },
    handleClose(e){
      this.handleOpen = false;
      if(e)this.getData();
    }

  }
};
</script>

<style>
</style>
